package com.atguigu.jdbc;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class JDBCDemo2 {

    @Test
    public void test(){
        //创建properties读取配置文件
        Properties p = new Properties();
        //创建流
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
        //加载流
        try {
            p.load(is);
            String url = p.getProperty("url");
            String driverClass = p.getProperty("driverClass");
            String password = p.getProperty("password");
            String username = p.getProperty("username");
            //Driver类加载
            Class.forName(driverClass);
            Connection connection = DriverManager.getConnection(url, username, password);
            System.out.println(connection);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
